package com.ly.lypopupwindowdemo.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import com.androidkun.xtablayout.XTabLayout;
import com.ly.lypopupwindowdemo.R;
import com.ly.lypopupwindowdemo.fragment.RefreshStyle1;
import com.ly.lypopupwindowdemo.fragment.RefreshStyle10;
import com.ly.lypopupwindowdemo.fragment.RefreshStyle11;
import com.ly.lypopupwindowdemo.fragment.RefreshStyle12;
import com.ly.lypopupwindowdemo.fragment.RefreshStyle13;
import com.ly.lypopupwindowdemo.fragment.RefreshStyle14;
import com.ly.lypopupwindowdemo.fragment.RefreshStyle15;
import com.ly.lypopupwindowdemo.fragment.RefreshStyle16;
import com.ly.lypopupwindowdemo.fragment.RefreshStyle17;
import com.ly.lypopupwindowdemo.fragment.RefreshStyle2;
import com.ly.lypopupwindowdemo.fragment.RefreshStyle3;
import com.ly.lypopupwindowdemo.fragment.RefreshStyle4;
import com.ly.lypopupwindowdemo.fragment.RefreshStyle5;
import com.ly.lypopupwindowdemo.fragment.RefreshStyle6;
import com.ly.lypopupwindowdemo.fragment.RefreshStyle7;
import com.ly.lypopupwindowdemo.fragment.RefreshStyle8;
import com.ly.lypopupwindowdemo.fragment.RefreshStyle9;

import java.util.ArrayList;
import java.util.List;


public class RefreshLibraryDemo extends AppCompatActivity {

    private ViewPager viewpager;
    List<Fragment> fragments = new ArrayList<>();
    List<String> titles = new ArrayList<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_refresh_library_demo);

        findViews();
        initViewPager();

    }


    private void initViewPager() {

        titles.add("ListView");
        titles.add("GridView");
        titles.add("RecyclerView");
        titles.add("Grid RecyclerView");
        titles.add("StaggeredGrid RecyclerView");
        titles.add("ScrollView");
        titles.add("WebView");
        titles.add("FrameLayout");
        titles.add("RelativeLayout");
        titles.add("LinearLayout");
        titles.add("ImageView");
        titles.add("TextView");
        titles.add("Google");
        titles.add("Custom");
        titles.add("JD Style");
        titles.add("Yalantis Style");

        fragments.add(new RefreshStyle1());
        fragments.add(new RefreshStyle2());
        fragments.add(new RefreshStyle3());
        fragments.add(new RefreshStyle4());
        fragments.add(new RefreshStyle5());
        fragments.add(new RefreshStyle6());
        fragments.add(new RefreshStyle7());
        fragments.add(new RefreshStyle8());
        fragments.add(new RefreshStyle9());
        fragments.add(new RefreshStyle10());
        fragments.add(new RefreshStyle11());
        fragments.add(new RefreshStyle12());
        fragments.add(new RefreshStyle13());
        fragments.add(new RefreshStyle14());
        fragments.add(new RefreshStyle15());
        fragments.add(new RefreshStyle16());



        FragmentAdapter fragmentAdapter = new FragmentAdapter(getSupportFragmentManager(), fragments, titles);
        viewpager.setAdapter(fragmentAdapter);
        viewpager.setOffscreenPageLimit(0);
       // XTabLayout tabLayout = (XTabLayout) findViewById(R.id.xTablayout);
        TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
        tabLayout.setupWithViewPager(viewpager);


    }

    private void findViews() {
        viewpager = (ViewPager) findViewById(R.id.viewpager);
    }

    class FragmentAdapter extends FragmentStatePagerAdapter {

        private List<Fragment> fragments;
        private List<String> titles;

        public FragmentAdapter(FragmentManager fm, List<Fragment> fragments, List<String> titles) {
            super(fm);
            this.fragments = fragments;
            this.titles = titles;
        }

        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return titles.get(position);
        }
    }
}
